package com.taiji.dicom4cloud.smart.rfid.handler;

import cn.hutool.core.util.ObjectUtil;
import com.taiji.dicom4cloud.common.core.constrant.CommonConstants;
import com.taiji.dicom4cloud.smart.model.entity.RfidEquipment;
import com.taiji.dicom4cloud.smart.rfid.annoation.HandlerType;
import com.taiji.dicom4cloud.smart.rfid.common.EnumHandler;
import com.taiji.dicom4cloud.smart.rfid.common.MessageHandler;
import com.taiji.dicom4cloud.smart.rfid.model.RfidMessage;
import com.taiji.dicom4cloud.smart.service.RfidEquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@HandlerType(value = EnumHandler.CONNECT)
public class ConnectHandler  implements MessageHandler {
    @Autowired
    private RfidEquipmentService rfidEquipmentService;
    @Override
    public Object handle(RfidMessage message) {
        RfidEquipment rfidEquipment = rfidEquipmentService.getByEquipmentId(message.getClientId());
        if(ObjectUtil.isNull(rfidEquipment)){
            log.error("CONNECT,接收到数据，找不到clientId："+message.getClientId());
            return null;
        }
        rfidEquipment.setIsConnect(CommonConstants.Status.CONNECT);
        rfidEquipmentService.updateById(rfidEquipment);
        return "connect";
    }
}